// packageI/components/footer/footer.js
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    auto_poster: {
      type: Number,
      value: 0
    },
    isset_poster: {
      type: Number,
      value: 0
    },
    activity_id: {
      type: Number,
      value: 0
    },
    staff_data: {
      type: Array,
      value: []
    },
    chat_data: {
      type: Object,
      value: {}
    },
    isRanking: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    posterFlag: false,
    staff_id: 0,
    posterSrc: "",
    imgPath: app.globalData.imgPath,
    serviceFlag: false
  },

  lifetimes: {
    attached() {
      // if(this.data.auto_poster==1 || this.data.isset_poster==1){
      //   this.getPoster();
      // }
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    watchImg(){
      wx.previewImage({
        current: this.data.posterSrc, // 当前显示图片的http链接
        urls: [this.data.posterSrc] // 需要预览的图片http链接列表
      })
    },
    setStaffId(evt) {
      this.setData({
        staff_id: evt.currentTarget.dataset.id
      });
    },
    setPosterFlag() {
      if (this.data.posterSrc) {
        this.setData({
          posterFlag: !this.data.posterFlag
        });
      } else if (this.data.auto_poster == 0 && this.data.isset_poster == 0) {
        this.setData({
          posterFlag: !this.data.posterFlag
        });
      } else {
        this.getPoster();
      }

    },
    getPoster() {
      let json = {
        id: this.data.activity_id
      };
      if (this.data.auto_poster == 0 && this.data.isset_poster == 0) {
        if (this.data.staff_id == 0) return app.tips("请选择企业成员");
        json.staff_id = this.data.staff_id;
      }
      let urlStr = app.getNetAddresss("plugin.customer-increase.frontend.activity.getPoster");
      app._postNetWork({
        url: urlStr,
        data: json,
        success: async (resdata) => {
          var res = resdata.data;
          if (res.result != 1) {
            if (res.data.need_agent == 1) {
              let flag = await app.confirm("您目前不是推广员，需要成为推广员才能生成海报。");
              if (flag) {
                wx.navigateTo({
                  url: '/packageA/member/extension/ExtensionApply/ExtensionApply'
                });
              }
              return;
            } else if (res.data.need_member_level == 1) {
              let levelStr = res.data.member_level.join(",");
              let flag = await app.confirm(`会员等级在【${levelStr}】才可以参与活动，您当前的会员等级暂不能参与活动，快去升级吧~`);
              if (flag) {
                wx.navigateTo({
                  url: '/packageB/member/MemberGradeList/MemberGradeList'
                });
              }
              return;
            } else {
              return app.tips(res.msg);
            }
          }

          this.setData({
            posterSrc: res.data.poster,
            posterFlag: true
          });
        },
      });
    },
    gotoRanking() {
      if (this.data.isRanking) return;
      wx.navigateTo({
        url: '/packageF/wxFriendExtend/friendRanking/friendRanking?id=' + this.data.activity_id,
      });
    },
    gotoChat(evt) {
      let url = evt.currentTarget.dataset.cservice;
      wx.navigateTo({
        url: url,
        fail: (err) => {
          app.tips("客服路由出错");
        }
      });
    },
    gotoIndex() {
      wx.navigateTo({
        url: '/pages/index/index',
      });
    },
    openService() {
      this.setData({
        serviceFlag: !this.data.serviceFlag
      });
    },
    callPhone() {
      wx.makePhoneCall({
        phoneNumber: this.data.chat_data.mobile,
      });
    },
  }
});